package com.seal.tsms.base.dao;



import java.util.Collection;

/**
 * 分页通用Bean
 * Created by seal.jing on 2015/12/24.
 */
public class Pagination {
    public final static  String COUNT_DC="countdc";//支持DetachedCriteria 查数量
    public final static  String RESULT_DC="resultdc";//支持DetachedCriteria 查记录
    public final static  String COUNT_HQL="counthql";//支持hql 查数量
    public final static  String RESULT_HQL="resulthql";//支持hql 查记录
    public final static  String PARAMS="params";//支持hql 查查询 参数
    public final static  String TRANSFORMER="resultTransformer";//查询结果转换器
    private int index;//页码
    private int size;//每页显示数目
    private int total;//总记录数
    private Collection<?> result;//查询结果
    private Object condition;//查询条件
    private String sort;//参与排序的字段
    private String order;//排序策略 asc  desc

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public Collection<?> getResult() {
        return result;
    }

    public void setResult(Collection<?> result) {
        this.result = result;
    }

    public Object getCondition() {
        return condition;
    }

    public void setCondition(Object condition) {
        this.condition = condition;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }
    //------------一下为只读属性-----------
    public int getTotalPaginationNumber(){

        return (int) Math.ceil(1.0*getTotal()/getSize());

    }
    public boolean isFirstPagination(){
         return getIndex()==1;
    }
    public boolean isLastPagination(){
        return getTotalPaginationNumber()==getIndex();
    }
    public int getFirstResult(){
        if(getTotal()==0){
            return 0;
        }
        return (getIndex()-1)*getSize()+1;
    }
    public int getLastResult(){
        if(getTotal()==0){
            return 0;
        }
        if(getTotalPaginationNumber()==getIndex()){
            return getTotal();
        }
        return getIndex()*getSize();
    }
}
